@extends('develop.layoutList')

@section('title')
    <li class="cur">
        <span>ACCESS TOKEN管理</span>
    </li>
@endsection

@section('btn')
    <button class="btn btn-primary" type="button" onclick="AccessToken.read();">查看当前TOKEN</button>
@endsection

@section('search')
    <input type="text" style="width:700px;margin-left: 7px;" class="form-control" name="access_token"  id="access_token" placeholder="请输入access_token">
@endsection

@section('js')
    <script>

        var bootstrap_table_ajax_url = '/lar/develop/access/search';
        bootstrap_table({
            sortName: 'createTime', //排序字段
            sortOrder: 'DESC',//排序方式
            columns: [ //字段
                { title: '创建人', field: 'creator', align: 'center'},
                { title: '创建时间', field: 'createTime', align: 'left'},
                { title: '获取方式', field: 'get_type', align: 'left' },
                { title: 'ACCESS_TOKEN',  field: 'access_token', align: 'left' }
            ]
        });

        var AccessToken = {

            //重置列表
            reset:function() {
                $('#access_token').val('');
                $('#table').bootstrapTable('refresh');
            },

            read: function ( uuid ) {
                var html ='<div class="panel-body">';

                html +='<div class="form-horizontal">';
                html +='<div class="form-group">';
                html +='<label for="accessToken" class="col-sm-2 control-label">access_token：</label>';
                html +='<div class="col-sm-8" style="float:left;">';
                html +='<textarea  rows="2" class="form-control" id="accessToken" style="word-break:break-all;height:150px;" disabled>{{$access_token or ''}}</textarea>';
                html +='</div>';
                html +='</div>';
                html +='<div class="form-group">';
                html +='<label class="col-sm-2 control-label"></label>';
                html +='<div class="col-sm-3">';
                html +='<button type="button" class="btn btn-primary" onclick="AccessToken.resetAccessToken();" style="margin-right:15px;" id="reset">重置</button>';
                html +='<button type="button" class="btn btn-primary" onclick="AccessToken.close();" id="reset">关闭</button>';
                html +='</div>';
                html +='</div>';
                html +='</div>';
                html +='</div>';

                layer.open({
                    type:1,
                    title:'当前TOKEN',
                    area:['700px','300px'],
                    content:html
                });
            },

            //重置token
            resetAccessToken: function() {
                var index = layer.load();
                E.ajax({
                    type:'get',
                    url: '/lar/develop/access/reset',
                    data: '',
                    success: function(o) {
                        layer.close(index);
                        if (o.code == 200) {
                            $('#accessToken').val(o.data);
                            layer.alert(o.message, {icon:1} );
                            AccessToken.reset();
                            setTimeout('E.layerClose();' ,1000 );
                        } else {
                            layer.alert(o.message, {icon:2} );
                        }
                    }
                });
            },
            //关闭
            close: function() {
                layer.closeAll();
            }
        };

    </script>
@endsection